﻿/**
* Logger.js
* 
* @author Demis Bellot
* @version 1.0
* @requres StringExt.js, ArrayExt.js
*
* Copyright 2009, Demis Bellot
* http://code.google.com/p/ajaxstack/
*/

function Logger(category)
{
	this.category = category;
}
Logger.extend(ASObject, { type: 'AjaxStack.Logger' }, {
	debug: function(message)
	{
		this.log("DEBUG", message);
	},

	info: function(message)
	{
		this.log("INFO", message);
	},

	warn: function(message)
	{
		this.log("WARN", message);
	},

	error: function(message)
	{
		Logger.errors++;
		this.log("ERROR", message);
	},

	fatal: function(message)
	{
		this.log("FATAL", message);
	},

	log: function(level, message)
	{
		if (!window.console) return;
		if (Logger.logLevels.length > 0 && !A.containsValue(Logger.logLevels, level)) return;
		if (Logger.logCategories.length > 0 && !A.containsValue(Logger.logCategories, this.category)) return;
		if (Logger.logAfterErrorNo && Logger.errors < Logger.logAfterErrorNo) return;
		if (Logger.logMessagesStartingWith.length > 0)
		{
			var messageStartsWithAFilter = A.any(Logger.logMessagesStartingWith,
				function(key, value)
				{
					return S.startsWith(message, value);
				});
			if (!messageStartsWithAFilter) return;
		}
		window.console.log(level + ": " + message);
	}
});

Logger.logCategories = [];
Logger.logLevels = [];
Logger.logMessagesStartingWith = [];
//Logger.logAfterErrorNo = 1;
Logger.errors = 0;
